package org.madmac.usuario;


import org.madmac.modulo.ModuloQuery;
import org.madmac.pessoa.PessoaQuery;
import org.wakeful.conn.Connection;
import org.wakeful.query.Query;
/**
 *
 * @author atila camurca
 */
public final class UsuarioQuery {

	public static final String TABLE = Connection.getSchema().concat(Query.DOT).concat("usuario");
   public static final String ALIAS = TABLE.concat(" u");

	private UsuarioQuery() {
	}
	
	public static String create() {
      StringBuilder builder = new StringBuilder();
      builder.append(Query.INSERT);
      builder.append(UsuarioQuery.TABLE);
      builder.append(" (login, senha, nickname, id_pessoa, id_modulo)");
      builder.append(Query.VALUES);
      builder.append("(?, MD5(?), ?, ?, ?)");
      builder.append(Query.RETURNING);
      builder.append("id_usuario");
      return builder.toString();
   }
   
   public static String retrieve() {
      StringBuilder builder = new StringBuilder();
      builder.append(Query.SELECT);
      builder.append("u.login, u.nickname, u.id_pessoa, p.nome, mod.descricao AS modulo");
      builder.append(Query.FROM);
      builder.append(UsuarioQuery.ALIAS);
      builder.append(Query.INNER_JOIN);
		builder.append(PessoaQuery.ALIAS);
		builder.append(Query.ON);
		builder.append("u.id_pessoa = p.id_pessoa");
      builder.append(Query.INNER_JOIN);
		builder.append(ModuloQuery.ALIAS);
		builder.append(Query.ON);
		builder.append("mod.id_modulo = u.id_modulo");
      builder.append(Query.WHERE);
      builder.append("u.id_usuario = ?");
      return builder.toString();
   }
   
   public static String update() {
      StringBuilder builder = new StringBuilder();
      builder.append("");
      return builder.toString();
   }
   
   public static String delete() {
      StringBuilder builder = new StringBuilder();
      builder.append("");
      return builder.toString();
   }
}
